BX.namespace("BX.rest.Marketplace");BX.rest.Marketplace=function(){var e="/bitrix/tools/rest.php";var t=function(t,a,o){a.action=t;a.sessid=BX.bitrix_sessid();BX.ajax({dataType:"json",method:"POST",url:e,data:a,onsuccess:o,onfailure:function(e,t){o({error:e+(!!t?": "+t:"")})}})};var a=function(e){var a={code:e.CODE};if(!!e.VERSION){a.version=e.VERSION}if(!!e.CHECK_HASH){a.check_hash=e.CHECK_HASH;a.install_hash=e.INSTALL_HASH}if(!!e.FROM){a.from=e.FROM}t("install",a,BX.delegate((function(t){var a=e.hasOwnProperty("DO_NOTHING")&&(e["DO_NOTHING"]==="Y"||e["DO_NOTHING"]===true);if(!!t.error){if(!!t.helperCode&&t.helperCode!==""){top.BX.UI.InfoHelper.show(t.helperCode)}var o=BX("mp_error");var s=t.error+(!!t.error_description?"<br />"+t.error_description:"");if(o){o.innerHTML=s;BX.show(o)}else{BX.UI.Notification.Center.notify({content:s})}}else if(!a&&!!t.redirect&&e["REDIRECT_PRIORITY"]===true){top.location.href=t.redirect}else if(!a&&!e.IFRAME){if(!!t.redirect){top.location.href=t.redirect}else{top.location.href=BX.util.remove_url_param(top.location.href,["install"])}}else{if(t.installed){var n={};top.BX.onCustomEvent(top,"Rest:AppLayout:ApplicationInstall",[true,n],false)}if(!a){if(!!t.open){BX.SidePanel.Instance.reload();top.BX.rest.AppLayout.openApplication(t.id,{})}else{BX.SidePanel.Instance.reload()}}}}),this))};return{install:function(e){if(!!e.SILENT_INSTALL&&e.SILENT_INSTALL==="Y"){a(e)}else{this.installPopup(e)}},installPopup:function(e){e=e||{url:location.href};e.IFRAME=location.href.indexOf("IFRAME=Y")>0;var t=false;var o=BX.PopupWindowManager.create("BXAppInstallPopup|"+e.url,null,{autoHide:false,zIndex:0,offsetLeft:0,offsetTop:0,overlay:true,draggable:{restrict:true},closeByEsc:true,closeIcon:{right:"12px",top:"10px"},buttons:[button=new BX.PopupWindowButton({text:BX.message("REST_MP_APP_INSTALL"),className:"popup-window-button-accept",events:{click:function(){if(!t){return}if(BX("mp_tos_license")&&!BX("mp_tos_license").checked){BX("mp_detail_error").innerHTML=BX.message("MARKETPLACE_LICENSE_TOS_ERROR_2");return}if(BX("mp_detail_license")&&!BX("mp_detail_license").checked||BX("mp_detail_confidentiality")&&!BX("mp_detail_confidentiality").checked){BX("mp_detail_error").innerHTML=BX.message("MARKETPLACE_LICENSE_ERROR");return}if(BX.hasClass(button.buttonNode,"popup-window-button-wait")){return}BX.addClass(button.buttonNode,"popup-window-button-wait");a(e)}}}),new BX.PopupWindowButtonLink({text:BX.message("REST_MP_APP_INSTALL_CANCEL"),className:"popup-window-button-link-cancel",events:{click:function(){this.popupWindow.close()}}})],content:'<div style="width:450px;height:230px; background: url(/bitrix/js/rest/images/loader.gif) no-repeat center;"></div>',events:{onAfterPopupShow:function(){var a=e.url||location.href;if(a.indexOf("?")>0){a+="&label=startInstall"}else{a+="?label=startInstall"}return BX.ajax({method:"POST",processData:false,url:a,data:BX.ajax.prepareData({install:1,sessid:BX.bitrix_sessid(),dataType:"json"}),onsuccess:BX.delegate((function(e){t=true;var a=BX.parseJSON(e);if(BX.type.isPlainObject(a)&&a["status"]=="success"){this.setContent(a["data"]["content"]);this.setTitleBar(a["data"]["title"])}else{this.setContent(e)}BX.defer(this.adjustPosition,this)()}),this)})}}});o.show()},uninstallConfirm:function(e,t){var a=new BX.PopupWindow("mp_delete_confirm_popup",null,{content:'<div class="mp_delete_confirm"><div class="mp_delete_confirm_text">'+BX.message("REST_MP_DELETE_CONFIRM")+'</div><div class="mp_delete_confirm_cb"><input type="checkbox" name="delete_data" id="delete_data">&nbsp;<label for="delete_data">'+BX.message("REST_MP_DELETE_CONFIRM_CLEAN")+"</label></div></div>",closeByEsc:true,closeIcon:{top:"1px",right:"10px"},buttons:[new BX.PopupWindowButton({text:BX.message("REST_MP_APP_DELETE"),className:"popup-window-button-decline",events:{click:function(){BX.rest.Marketplace.uninstall(e,BX("delete_data").checked,(function(e){if(e.error){a.setContent('<div class="mp_delete_confirm"><div class="mp_delete_confirm_text">'+e.error+"</div></div>");a.setButtons([new BX.PopupWindowButtonLink({text:BX.message("JS_CORE_WINDOW_CLOSE"),className:"popup-window-button-link-cancel",events:{click:function(){this.popupWindow.close()}}})]);a.adjustPosition()}else{if(!!e.sliderUrl){BX.SidePanel.Instance.open(e.sliderUrl)}else{a.close();window.location.reload()}}}),t)}}}),new BX.PopupWindowButtonLink({text:BX.message("JS_CORE_WINDOW_CANCEL"),className:"popup-window-button-link-cancel",events:{click:function(){this.popupWindow.close()}}})]});a.show()},uninstall:function(e,a,o,s){t("uninstall",{code:e,clean:a,from:s},(function(e){var t={};top.BX.onCustomEvent(top,"Rest:AppLayout:ApplicationInstall",[false,t],false);if(!!o){o(e)}else{if(!!e.error){BX.UI.Notification.Center.notify({content:e.error})}else{location.reload()}}}))},reinstall:function(e,a){t("reinstall",{id:e},(function(e){if(!!e.error){if(!!e.helperCode&&e.helperCode!==""){top.BX.UI.InfoHelper.show(e.helperCode)}else{BX.UI.Notification.Center.notify({content:e.error})}}else if(!!e.redirect){BX.reload(e.redirect)}else{BX.UI.Notification.Center.notify({content:BX.message("REST_MP_APP_REINSTALLED")})}if(!!a){a()}}))},buy:function(e,t){var a=[];for(var o=0;o<t.length;o++){a.push({text:t[o].TEXT,href:t[o].LINK,target:"_blank",className:"menu-popup-no-icon"})}BX.PopupMenu.show("user-menu",e,a,{offsetTop:9,offsetLeft:43,angle:true})},buySubscription:function(e){var t=[];var a=BX.message("CAN_BUY_SUBSCRIPTION");var o=BX.message("CAN_ACTIVATE_DEMO_SUBSCRIPTION");if(!!a&&a==="Y"){t.push(new BX.PopupWindowButton({text:BX.message("REST_MP_SUBSCRIPTION_BUTTON_TITLE"),className:"popup-window-button-accept",events:{click:this.openBuySubscription}}))}if(!!o&&o==="Y"){t.push(new BX.PopupWindowButtonLink({text:BX.message("REST_MP_SUBSCRIPTION_BUTTON_TITLE2"),className:"popup-window-button-link-cancel",events:{click:function(){this.openDemoSubscription()}.bind(this)}}))}var s=BX.PopupWindowManager.create("marketplace_buy_subscription",null,{content:BX.create("div",{props:{className:"rest-marketplace-popup-block"},children:[BX.create("div",{props:{className:"rest-marketplace-popup-text-block"},children:[BX.create("div",{props:{className:"rest-marketplace-popup-text"},text:BX.message("REST_MP_SUBSCRIPTION_TEXT_1")}),BX.create("div",{props:{className:"rest-marketplace-popup-text"},text:BX.message("REST_MP_SUBSCRIPTION_TEXT_2")}),BX.create("div",{props:{className:"rest-marketplace-popup-text"},children:[BX.create("div",{props:{className:"rest-marketplace-popup-text"},html:BX.message("REST_MP_SUBSCRIPTION_TEXT_3").replace("#ONCLICK#","BX.rest.Marketplace.open(null,'subscription')")}),BX.create("ul",{children:[BX.create("li",{text:BX.message("REST_MP_SUBSCRIPTION_TEXT_3_LI_1")}),BX.create("li",{text:BX.message("REST_MP_SUBSCRIPTION_TEXT_3_LI_2")}),BX.create("li",{text:BX.message("REST_MP_SUBSCRIPTION_TEXT_3_LI_3")}),BX.create("li",{text:BX.message("REST_MP_SUBSCRIPTION_TEXT_3_LI_4")}),BX.create("li",{text:BX.message("REST_MP_SUBSCRIPTION_TEXT_3_LI_5")}),BX.create("li",{text:BX.message("REST_MP_SUBSCRIPTION_TEXT_3_LI_6")})]})]}),BX.create("div",{props:{className:"rest-marketplace-popup-text"},html:BX.message("REST_MP_SUBSCRIPTION_TEXT_4").replace("#ONCLICK#","top.BX.Helper.show('redirect=detail&code=12154172');")}),BX.create("div",{props:{className:"rest-marketplace-popup-text"},text:BX.message("REST_MP_SUBSCRIPTION_TEXT_5")})]})]}),titleBar:BX.message("REST_MP_SUBSCRIPTION_TITLE"),closeIcon:true,closeByEsc:true,draggable:true,lightShadow:true,overlay:true,className:"landing-marketplace-popup-wrapper",buttons:t}).show()},openBuySubscription:function(){var e=BX.message("REST_BUY_SUBSCRIPTION_URL");if(e!==""){top.window.open(e,"_blank")}else{BX.UI.Notification.Center.notify({content:BX.message("REST_MP_SUBSCRIPTION_ERROR_OPEN_BUY_URL")})}},openDemoSubscription:function(e){var a=new BX.UI.Button({color:BX.UI.Button.Color.SUCCESS,state:BX.UI.Button.State.DISABLED,text:BX.message("REST_MP_SUBSCRIPTION_BUTTON_DEMO_ACTIVE"),className:"rest-marketplace-popup-activate-subscription-btn",onclick:BX.delegate((function(){if(BX("mp_demo_subscription_license").checked){a.setState(BX.UI.Button.State.WAITING);t("activate_demo",{},(function(t){if(!!t.error){BX.UI.Notification.Center.notify({content:t.error});a.setState(BX("mp_demo_subscription_license").checked?BX.UI.Button.State.ACTIVE:BX.UI.Button.State.DISABLED)}else{if(BX.type.isFunction(e)){e(t)}else{var o=BX.SidePanel.Instance.getTopSlider();if(!!o){o.reload()}else{window.location.reload()}}}}))}}),this)});var o=BX.PopupWindowManager.create("marketplace_demo_subscription",null,{content:BX.create("div",{props:{className:"rest-marketplace-popup-block"},children:[BX.create("div",{props:{className:"rest-marketplace-popup-text-block"},children:[BX.create("div",{props:{className:"rest-marketplace-popup-text"},text:BX.message("REST_MP_SUBSCRIPTION_DEMO_TITLE")}),BX.create("div",{props:{className:"rest-marketplace-popup-text"},html:BX.message("REST_MP_SUBSCRIPTION_DEMO_TEXT_1").replace("#ONCLICK#","BX.rest.Marketplace.open(null,'subscription')")}),BX.create("div",{props:{className:"rest-marketplace-popup-text"},text:BX.message("REST_MP_SUBSCRIPTION_DEMO_TEXT_2")}),BX.create("div",{style:{"margin-bottom":"8px","margin-top":"15px"},children:[BX.create("input",{attrs:{id:"mp_demo_subscription_license",type:"checkbox",name:"ACCEPT_SUBSCRIPTION_LICENSE",value:"Y"},events:{change:function(e){a.setState(e.target.checked?BX.UI.Button.State.ACTIVE:BX.UI.Button.State.DISABLED)}}}),BX.create("label",{attrs:{for:"mp_demo_subscription_license"},html:BX.message("REST_MP_SUBSCRIPTION_DEMO_EULA_TITLE").replace("#LINK#",BX.message("REST_MP_SUBSCRIPTION_DEMO_EULA_LINK"))})]})]})]}),titleBar:BX.message("REST_MP_SUBSCRIPTION_TITLE"),closeIcon:true,closeByEsc:true,draggable:true,lightShadow:true,overlay:true,className:"landing-marketplace-popup-wrapper",buttons:[a,new BX.PopupWindowButtonLink({text:BX.message("JS_CORE_WINDOW_CANCEL"),className:"popup-window-button-link-cancel",events:{click:function(){this.popupWindow.close()}}})]}).show()},setRights:function(e,a){BX.Access.Init({other:{disabled:false,disabled_g2:true,disabled_cr:true},groups:{disabled:true},socnetgroups:{disabled:true}});var o={app_id:e};if(!!a){o.site_id=a}t("get_app_rigths",o,(function(o){BX.Access.SetSelected(o,"bind");BX.Access.ShowForm({bind:"bind",showSelected:true,callback:function(o){var s={app_id:e,rights:o};if(!!a){s.site_id=a}t("set_app_rights",s,(function(e){}))}})}))},open:function(e,t){if(!t){t="all"}var a=BX.message("REST_MARKETPLACE_CATEGORY_URL").replace("#CODE#",t);if(!!e&&!!e.PLACEMENT){a=BX.util.add_url_param(a,{placement:e.PLACEMENT,category:t})}else{a=BX.util.add_url_param(a,{category:t})}var o=BX.SidePanel.Instance.getUrlRule(a);var s=o&&BX.type.isPlainObject(o.options)?o.options:{};s["cacheable"]=false;s["allowChangeHistory"]=false;s["requestMethod"]="post";s["requestParams"]={sessid:BX.bitrix_sessid()};BX.SidePanel.Instance.open(a,s);var n=BX.SidePanel.Instance.getTopSlider();top.BX.addCustomEvent(top,"Rest:AppLayout:ApplicationInstall",(function(e,t){t.redirect=false}))},bindPageAnchors:function(e){BX.ready((function(){BX.SidePanel.Instance.bindAnchors(top.BX.clone({rules:[{condition:["/marketplace/detail/","/bitrix/components/bitrix/rest.marketplace/lazyload.ajax.php"],options:{cacheable:false,allowChangeHistory:e.allowChangeHistory}}]}))}))}}}();
//# sourceMappingURL=marketplace.map.js